package loppy.dynamics 
{
  import loppy.loppy_internal;
  
  public class Proxy 
  {
    use namespace loppy_internal;
    
    loppy_internal var minX:Number = 0.0;
    loppy_internal var minY:Number = 0.0;
    loppy_internal var maxX:Number = 0.0;
    loppy_internal var maxY:Number = 0.0;
    
    loppy_internal var parent:Shape = null;
    
    public function Proxy() 
    { }
    
    public function copy(from:Proxy):Proxy
    {
      minX = from.minX;
      minY = from.minY;
      maxX = from.maxX;
      maxY = from.maxY;
      return this;
    }
    
    public function contains(rhs:Proxy):Boolean
    {
      return (minX <= rhs.minX) 
          && (minY <= rhs.minY)
          && (maxX >= rhs.maxX)
          && (maxY >= rhs.maxY);
    }
    
    public function intersects(rhs:Proxy):Boolean
    {
      return (minX < rhs.maxX)
          && (maxX > rhs.minX)
          && (minY < rhs.maxY)
          && (maxY > rhs.minY);
    }
    
    public function encompass(target:Proxy):Proxy
    {
      minX = Math.min(minX, target.minX);
      minY = Math.min(minY, target.minY);
      maxX = Math.max(maxX, target.maxX);
      maxY = Math.max(maxY, target.maxY);
      return this;
    }
    
    public function toString():String
    {
			return "[Proxy" + " minX=" + minX + ", minY=" + minY + ", maxX=" + maxX + ", maxY=" + maxY + "]";
		}
  }
}
